<?php

class Model_testimonial extends CI_Model{
	function __construct()
	{
        parent::__construct();
	}
	
	function getTestimonial($params=array())
	{
		$this->db->select("*");
		$this->db->from("testimonial");
		$this->db->join("user","user.user_id=testimonial.user_id");
		if(isset($params['is_shown']) ) $this->db->where("is_shown",$params['is_shown']);
		
		if(isset($params['testimonial_id']) )$this->db->where("testimonial_id",$params['testimonial_id']);
		if(isset($params['order_by']) ){
			$this->db->order_by($params['order_by']);
		}else{
			$this->db->order_by("entry_date desc, testimonial_id desc");
		}
		if(isset($params['limit_1'])  && isset($params['limit_2']) ) $this->db->limit($params['limit_1'],$params['limit_2']);
		
		$res = $this->db->get();
		if($res->num_rows() > 0)
			return $res->result_array();
		else
			return array();
	}
	function changestatus($testimonial_id,$status){
		$data = array(
               'is_shown' => $status
            );

		$this->db->where('testimonial_id', $testimonial_id);
		$this->db->update('testimonial', $data); 
	}
	function save($desc){
		$data = array(
               'desc' => $desc,
			   'entry_date' => date("Y-m-d H:i:s"),
			   'user_id' => $this->session->userdata("user_id"),
			   'is_shown' => 'N'
            );

		$this->db->insert('testimonial', $data); 
	}

}
?>